package com.samtech.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class DefaultRequestController {
	@RequestMapping(path="**.html",method=RequestMethod.GET)
	public String defaultRequest(HttpServletRequest request) {
		return resolverContextPath(request);
	}
	@RequestMapping(path="/*/**.html",method=RequestMethod.GET)
	public String defaultsubRequest(HttpServletRequest request) {
		return resolverContextPath(request);
	}
	private String resolverContextPath(HttpServletRequest request) {
		String ctxpath = request.getContextPath();
		String requestURI = request.getRequestURI();
		String viewname=requestURI;
		if(ctxpath!=null && ctxpath.trim().length()>1  ) {
			int idx = requestURI.indexOf(ctxpath);
			if(idx>=0 && idx<2) {
				viewname = requestURI.substring(idx+ctxpath.length());
			}
		}
		System.out.println("pathInfo:"+viewname);
		return viewname;
	}
}
